package MallOrderStatistics

import (
	"errors"
	"fmt"
	CoreSQL "gitee.com/fotomxq/weeekj_core/v5/core/sql"
	Router2SystemConfig "gitee.com/fotomxq/weeekj_core/v5/router2/system_config"
	"github.com/lib/pq"
)

type ArgsOrderStatisticsUpdate struct {
	//Ids
	Ids pq.Int64Array `json:"ids"`
	//支付ID
	PayId int64 `json:"pay_id"`
}

// OrderStatisticsUpdate 更新大客户清缴订单id
func OrderStatisticsUpdate(args *ArgsOrderStatisticsUpdate) (err error, errCode string) {
	if _, err = CoreSQL.UpdateOneSoft(Router2SystemConfig.MainDB.DB, "UPDATE mall_order_statistics SET pay_id = :pay_id WHERE id = ANY(:ids)", map[string]interface{}{
		"pay_id": args.PayId,
		"ids":    args.Ids,
	}); err != nil {
		errCode = "order_update_pay_id"
		err = errors.New(fmt.Sprint("order update pay id, ", err))
		return
	}
	return
}

// OrderStatisticsUpdateById 根据id更新清缴单状态
func OrderStatisticsUpdateById(Id int64, des string) (err error) {
	_, err = CoreSQL.UpdateOneSoft(Router2SystemConfig.MainDB.DB, "UPDATE mall_order_statistics SET status = :status,des =:des WHERE id = :id", map[string]interface{}{
		"id":     Id,
		"des":    des,
		"status": 1,
	})
	return
}
